package com.njworkorder.Service.Impl;

import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.njworkorder.Entity.*;
import com.njworkorder.Service.AssignmentWithDiseaseService;
import com.njworkorder.Mapper.AssignmentWithDiseaseMapper;
import com.njworkorder.VO.AssignmentProgressVos.ComponentsInfo;
import com.njworkorder.VO.AssignmentProgressVos.DRInfo;
import com.njworkorder.VO.AssignmentProgressVos.IRInfo;
import com.njworkorder.VO.AssignmentProgressVos.RepairInformationInfo;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
* @author iron
* @description 针对表【assignment_with_disease】的数据库操作Service实现
* @createDate 2024-11-26 09:31:39
*/
@Service
public class AssignmentWithDiseaseServiceImpl extends MPJBaseServiceImpl<AssignmentWithDiseaseMapper, AssignmentWithDisease>
    implements AssignmentWithDiseaseService{

    @Async
    @Override
    public CompletableFuture<List<DRInfo>> getDRInfo(String assignmentId) {
        MPJLambdaWrapper<AssignmentWithDisease> wrapperDRInfo = new MPJLambdaWrapper<AssignmentWithDisease>()
                .selectAs(DiseaseRegistration::getInspectionRegistrationId,DRInfo::getIRId)
                .selectAs(DiseaseRegistration::getDiseaseModule, DRInfo::getDiseaseModule)
                .selectAs(DiseaseRegistration::getDataSources,DRInfo::getDataSources)
                .selectAs(Disease::getDiseaseName,DRInfo::getDiseaseName)
                .selectAs(DiseaseRegistration::getUrgency,DRInfo::getUrgency)
                .selectAs(DiseaseRegistration::getRepairLabel,DRInfo::getRepairLabel)
                .selectAs(DiseaseRegistration::getAppendixes,DRInfo::getAppendixes)
                .selectAs(DiseaseRegistration::getImagePath,DRInfo::getImagePath)
                .selectAs(DiseaseRegistration::getPosition,DRInfo::getPosition)
                .selectAs(DiseaseRegistration::getEstimatedWorkload,DRInfo::getEstimatedWorkload)

                .leftJoin(DiseaseRegistration.class,DiseaseRegistration::getId,AssignmentWithDisease::getDiseaseId)
                .leftJoin(Disease.class,Disease::getId,DiseaseRegistration::getDisease)
                .leftJoin(Dictionary.class,Dictionary::getId,DiseaseRegistration::getDirection,ext ->
                        ext.selectAs(Dictionary::getValusas,DRInfo::getDirection))
                .leftJoin(Dictionary.class,Dictionary::getId,DiseaseRegistration::getLane,ext ->
                        ext.selectAs(Dictionary::getValusas,DRInfo::getLane))

                .eq(AssignmentWithDisease::getAssignmentId,assignmentId);
        return CompletableFuture.completedFuture(selectJoinList(DRInfo.class, wrapperDRInfo));
    }

    @Async
    @Override
    public CompletableFuture<List<IRInfo>> getIRInfo(String assignmentId) {
        MPJLambdaWrapper<AssignmentWithDisease> wrapperIRInfo = new MPJLambdaWrapper<AssignmentWithDisease>()
                .selectAs(InspectionRegistration::getId,IRInfo::getId)
                .selectAs(InspectionRegistration::getStartPileNumUp,IRInfo::getStartPileNumUp)
                .selectAs(InspectionRegistration::getEndPileNumUp,IRInfo::getEndPileNumUp)
                .selectAs(InspectionRegistration::getStartPileNumDown,IRInfo::getStartPileNumDown)
                .selectAs(InspectionRegistration::getEndPileNumDown,IRInfo::getEndPileNumDown)
                .selectAs(Workspace::getWorkspaceName,IRInfo::getWorkspaceName)
                .selectAs(InspectionRegistration::getInspectionType,IRInfo::getInspectionType)
                .selectAs(InspectionRegistration::getRemark,IRInfo::getRemark)
                .selectAs(InspectionRegistration::getRemark,IRInfo::getRemark)
                .selectAs(Section::getSectionName,IRInfo::getSectionName)
                .selectAs(InspectionRegistration::getInspectionStartTime,IRInfo::getInspectionStartTime)
                .selectAs(Route::getRouteName,IRInfo::getRouteName)

                .leftJoin(DiseaseRegistration.class,DiseaseRegistration::getId,AssignmentWithDisease::getDiseaseId)
                .leftJoin(InspectionRegistration.class,InspectionRegistration::getId,DiseaseRegistration::getInspectionRegistrationId)
                .leftJoin(Workspace.class,Workspace::getId,InspectionRegistration::getWorkspaceId)
                .leftJoin(Section.class,Section::getId,InspectionRegistration::getSectionId)
                .leftJoin(Route.class,Route::getId,Section::getRouteId)
                .eq(AssignmentWithDisease::getAssignmentId,assignmentId)
                .groupBy(InspectionRegistration::getId);

        return CompletableFuture.completedFuture(selectJoinList(IRInfo.class, wrapperIRInfo));
    }

    @Async
    @Override
    public CompletableFuture<List<RepairInformationInfo>> getRepairInformationInfo(String assignmentId) {

        MPJLambdaWrapper<AssignmentWithDisease> wrapper = new MPJLambdaWrapper<AssignmentWithDisease>()

                .selectAs(AssignmentWithDisease::getRepairStartTime,RepairInformationInfo::getRepairStartTime)
                .selectAs(AssignmentWithDisease::getEndTimeMaintenance,RepairInformationInfo::getEndTimeMaintenance)
                .selectAs(AssignmentWithDisease::getQualitySelfAssessment,RepairInformationInfo::getQualitySelfAssessment)
                .selectAs(DiseaseRegistration::getEstimatedWorkload,RepairInformationInfo::getDrBoq)

                .selectAs(AssignmentWithDisease::getDescription,RepairInformationInfo::getDescription)
                .selectAs(AssignmentWithDisease::getBeforeMaintenanceImg,RepairInformationInfo::getBeforeMaintenanceImg)
                .selectAs(AssignmentWithDisease::getUnderRepairImg,RepairInformationInfo::getUnderRepairImg)
                .selectAs(AssignmentWithDisease::getAfterRepairImg,RepairInformationInfo::getAfterRepairImg)

                .selectAs(EngineeringQualityInfo::getId,RepairInformationInfo::getEqiId)
                .selectAs(EngineeringQualityInfo::getConstructionMaterials,RepairInformationInfo::getConstructionMaterials)
                .selectAs(EngineeringQualityInfo::getAppearanceAppraisal,RepairInformationInfo::getAppearanceAppraisal)
                .selectAs(MaintenanceContent::getContentName,RepairInformationInfo::getContentName)

                .leftJoin(DiseaseRegistration.class,DiseaseRegistration::getId,AssignmentWithDisease::getDiseaseId)

                .leftJoin(EqiWithDr.class,EqiWithDr::getDiseaseRegistrationId,AssignmentWithDisease::getDiseaseId)
                .leftJoin(EngineeringQualityInfo.class,EngineeringQualityInfo::getId,EqiWithDr::getEqiId)


                .leftJoin(ConstructionIndicators.class,ConstructionIndicators::getId,EngineeringQualityInfo::getCiId,ext ->
                        ext.selectAs(ConstructionIndicators::getIndicatorsName,RepairInformationInfo::getIndicatorsName))
                .leftJoin(ConstructionIndexItems.class,ConstructionIndexItems::getId,EngineeringQualityInfo::getCiiId,ext ->
                        ext.selectAs(ConstructionIndexItems::getIndexItemsName,RepairInformationInfo::getIndexItemsName))

                .leftJoin(MaintenanceContent.class,MaintenanceContent::getId,EngineeringQualityInfo::getMcId)

                .eq(AssignmentWithDisease::getAssignmentId,assignmentId);

        return CompletableFuture.completedFuture(selectJoinList(RepairInformationInfo.class, wrapper));
    }

    @Async
    @Override
    public CompletableFuture<List<ComponentsInfo>> getComponentsInfos(String assignmentId) {

        MPJLambdaWrapper<AssignmentWithDisease> wrapper = new MPJLambdaWrapper<AssignmentWithDisease>()

                .selectAs(Components::getNums,ComponentsInfo::getNums)
                .selectAs(Parts::getPartsName,ComponentsInfo::getPartsName)
                .selectAs(Parts::getUnit,ComponentsInfo::getUnit)
                .selectAs(ModelNum::getModelName,ComponentsInfo::getModelName)
                .selectAs(MaintenanceMethod::getMethodName,ComponentsInfo::getMethodName)

                .rightJoin(Components.class,Components::getDiseaseRegistrationId,AssignmentWithDisease::getDiseaseId)
                .leftJoin(Parts.class,Parts::getId,Components::getPartsId)
                .leftJoin(ModelNum.class,ModelNum::getId,Components::getModelNumId)
                .leftJoin(MaintenanceMethod.class,MaintenanceMethod::getId,Components::getMaintenanceMethodId)

                .eq(AssignmentWithDisease::getAssignmentId,assignmentId);

        return CompletableFuture.completedFuture(selectJoinList(ComponentsInfo.class, wrapper));
    }


}




